﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using YWTSSys.BLL;
using YWTSSys.Library;
using YWTSSys.Model;
using System.Text;

namespace YWTSSys.Web.MachineSys.YWTSWeb.dy
{
    public partial class AddCustomer : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get { return "CustomerConsumeMaster"; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }
        private void addmenu()
        {
            CustomerInfo obj = Request.SerializableObject<CustomerInfo>();
            //obj.客户ID = CustomerId;
            //obj.UserId = base.User.UserId;
            //obj.RealName = base.User.RealName;
            //obj.回访电话记录ID = ParTelId;
            //decimal 通话时长 = 0m;
            //TimeSpan ts = DateTime.Now - obj.通话时间; ;
            //通话时长 = ts.Seconds;
            //obj.通话时长 = 通话时长;

            //int 需回访天数 = GetRequestValue<int>("需回访天数", 0);

            AddLog(Permission.新增, obj);

            // obj.UserName = GetRequestValue<string>("dwz.orgLookup.UserName", "");

            int r = CustomerController.Add(obj);

            if (r > 0)
                SuccessJson("添加成功");
            else
            {
                ErrorJson("添加失败");
            }
        }


        protected string GetFolderTree(string selvalue)
        {
            List<CustomerGroupInfo> listArea = CustomerGroupController.GetAllArea();
            if (listArea.Count <= 0)
                return "";

            /// <ul><li><a href="JSDWF/JSDWFFolderPageList.aspx?ParFolderID=1" target="ajax" rel="jbsxBox">尿检</a></li></ul>
            StringBuilder sb = new StringBuilder();

            foreach (CustomerGroupInfo itm in listArea)
            {

                sb.AppendFormat("<optgroup label=\"{0}\" >{0}</optgroup>", itm.分组标志);

                sb.Append(GetGrouppTree(itm.分组标志, selvalue));


            }
            // sb.Append("</ul>");

            return sb.ToString();
        }

        protected string GetGrouppTree(string areaName, string selvalue)
        {
            DataTable listArea = CustomerGroupController.GetAllGroupByArea(areaName);
            if (listArea.Rows.Count <= 0)
                return "";

            /// <ul><li><a href="JSDWF/JSDWFFolderPageList.aspx?ParFolderID=1" target="ajax" rel="jbsxBox">尿检</a></li></ul>
            StringBuilder sb = new StringBuilder();

            foreach (DataRow itm in listArea.Rows)
            {

                // sb.AppendFormat("<a href=\"YWTSWeb/GL/CustomerGroupGroupList.aspx?AreaName={0}\" target=\"ajax\" rel=\"CustomerGroupGroupList\">{1}</a>", HttpUtility.UrlEncode(itm.分组标志), itm.分组标志);
                sb.AppendFormat("<option value=\"{0}\" {1}>&nbsp;&nbsp;{0}</option>", itm["分组标志"], selvalue == itm["分组标志"].ToString() ? "selected" : "");

            }


            return sb.ToString();
        }
    }
}